<a href="../">&lt; Back </a>
<?php
	require_once 'lib/settings.php';
	require_once 'lib/smtpmail/phpmailer.class.php';
	
	if (isset($_POST['send'])) {
		$to = $_POST['to'];
		$subject = $_POST['subj'];
		$message = $_POST['msg'];
		$cc = $_POST['cc'];
		$from = $_POST['from'];
		sendHTMLemail($to, $subject, $message, $cc, $from);
	}
	
	/**
    * Send email
    * 
    * @param mixed $message
    * @param mixed $from
    * @param mixed $to
    * @param mixed $subject
    */
    function sendHTMLemail($to, $subject, $message, $cc = null, $from = null)
    {
    	//send mail by using php smtp mailer
        try {
            	
            $mail = new PHPMailer(true); 
            $mail->IsSMTP();
            $mail->SMTPDebug  = 0;                

            $mail->SMTPAuth   = SMTP_MAIL_AUTH;             
            $mail->SMTPSecure = SMTP_MAIL_SECURE;            
            $mail->Host       = SMTP_MAIL_HOST;
            $mail->Port       = SMTP_MAIL_PORT;  
            $mail->Username   = SMTP_MAIL_USER_NAME;  
            $mail->Password   = SMTP_MAIL_PASSWORD;
            $mail->From		=	SMTP_MAIL_FROM;
            $mail->FromName	=	SMTP_MAIL_FROM_NAME;

            $mail->AddAddress($to, $to);
            if (isset($cc)) $mail->AddCC($cc, $cc);
            if (isset($from)) $mail->SetFrom($from, $from);
            $mail->ContentType = "text/html";
            $mail->CharSet = "UTF-8";
            $mail->Subject = $subject;
            $mail->MsgHTML($message);
            $mail->Send();
        } catch(Exception $e) {
			echo $e;
        }     
    }
?>
<br />* rename lib/settings.sample.php to lib/settings.php and setup your account in it first
<br />* php_openssl must be installed and enable
<form method="post" action="">
	<fieldset style="display: inline-block">
	<legend><h2>Send an E-Mail</h2></legend>
	<table style="background-color: #CCC">
		<tr><th>From</th><td><input type="text" name="from" placeholder="thaidacvinh@gmail.com" size="50" /></td></tr>
		<tr><th>To</th><td><input type="text" name="to" placeholder="huong.duongto@gmail.com" size="50" /></td></tr>
		<tr><th>Cc</th><td><input type="text" name="cc" placeholder="albertthai@gmail.com" size="50" /></td></tr>
		<tr><th>Subject</th><td><input type="text" name="subj" placeholder="Testing Mail" size="50" /></td></tr>
		<tr><th>Message</th><td><textarea name="msg" cols="100" rows="10"></textarea></td></tr>
		<tr><td></td><td><input type="submit" name="send" value="Send" /></td></tr>
	</table>
	</fieldset>
</form>
